/******************************************************************************
* This file is part of is32p218 platform,
* Copyright (c) 2009 HangZhou InfoStrong CO.,LTD. All rights reserved.
* This software may only be used under the terms of a valid, current,
* end user license from InfoStrong.
* Nothing else gives you the right to use this software.   
*
* Name:   plc_api.c
* Desc:   PLC module API C file
* Author: Jerry
* Date:   2009-11-4
* Note:   
* History:
*
******************************************************************************/
#include "plc_hl.h"
#include "plc_if.h"
#include "plc_api.h"
#include "mw_nram.h"
#include "plc.h"
extern PLC_HL_CTRL_T g_plc_hl_ctrl;


/*
* Function Name:
*   plc_api_mac_set
* Description:
*   Set local MAC address
* Parameters:
*   U8* p_mac_data:
* Returns:
* Author				Date 
*  Jerry				2009-11-27   
* Note:
*    
*/
void plc_api_mac_set( U8 *p_mac_data )
{
#if 0
	PLC_IF_PARAMS plc_params;

	isOS_memset( &plc_params, 0x00, sizeof(plc_params) );
	if ( bu_mw_Nram_read( NRAM_ITEM_PLC_PARAMS, 0, sizeof(PLC_IF_PARAMS), (U8*)&plc_params ) )
	{
		isOS_memcpy( plc_params.m_mac, p_mac_data, PLC_PH_MAC_LEN );
		if ( !bu_mw_Nram_write( NRAM_ITEM_PLC_PARAMS, 0, (U8*)&plc_params, sizeof(PLC_IF_PARAMS) ) )
		{
			IS_ASSERT(0);
		}
	}
#endif
#if (defined(MASTER_NODE)&&defined(PLC_MAC_BIND))
	if (isOS_memcmp( p_mac_data, plc_pl_mac_get(0), PLC_PH_MAC_LEN) )
	{	// If MAC address is changed, should Bind again
		plc_hl_msg_trans( MSG_PLC_TO_PLC_MAC_BIND_START );
	}
	
#endif
	plc_pl_mac_set( 0, (U8*)p_mac_data, sizeof(MAC_ADDR_T) );
}

/*
* Function Name:
*   plc_api_mac_get
* Description:
*   Get local MAC address
* Parameters:
* Returns:
*   U8*:
* Author				Date 
*  Jerry				2009-11-27   
* Note:
*    
*/
const U8* plc_api_mac_get( void  )
{
	//return (U8*)&g_plc_hl_ctrl.m_local_mac;
	return (const U8*)plc_pl_mac_get( 0 );
}

/*
* Function Name:
*   plc_api_params_set
* Description:
*   PLC Parameters Set
* Parameters:
*   PLC_PARAMS_T* p_plc_para:
* Returns:
* Author				Date 
*  Jerry				2010-4-13   
* Note:
*    
*/
void plc_api_params_set( const PLC_PARAMS_T *p_plc_para )
{
	plc_if_params_set( (const PLC_IF_PARAMS *)p_plc_para);
}
#if (defined(XN5106C_EXT)) && defined(MASTER_NODE)
/*
* Function Name:
*   plc_api_master_params_set
* Description:
*   PLC MASTER Parameters Set
* Parameters:
*   PLC_MASTER_PARAMS_T* p_plc_para:
* Returns:
* Author				Date 
*  Nicky				2012-9-5   
* Note:
*    
*/
void plc_api_master_params_set( const PLC_MASTER_PARAMS_T *p_plc_para )
{
	plc_if_master_params_set( (const PLC_MASTER_PARAMS_T *)p_plc_para);
}
#endif
#if (!defined(MASTER_NODE)&&(defined(PLC_VOID_COLLUDE)||defined(PLC_MAC_BIND)))
/*
* Function Name:
*   plc_api_dc_mac_set
* Description:
*   Set DC MAC address
* Parameters:
*   U8* p_mac_data:
* Returns:
* Author				Date 
*  Jerry				2009-11-27   
* Note:
*    
*/
void plc_api_dc_mac_set( U8 *p_mac_data )
{
	plc_pl_dc_mac_set( (U8*)p_mac_data );
}

/*
* Function Name:
*   plc_api_dc_mac_get
* Description:
*   Get DC MAC address
* Parameters:
* Returns:
*   U8*:
* Author				Date 
*  Jerry				2009-11-27   
* Note:
*    
*/
const U8* plc_api_dc_mac_get( void  )
{
	//return (U8*)&g_plc_hl_ctrl.m_local_mac;
	return (const U8*)plc_pl_dc_mac_get();
}
#endif
/*
* Function Name:
*   plc_api_params_get
* Description:
*   PLC Parameters Get
* Parameters:
* Returns:
*   const PLC_PARAMS_T*:
* Author				Date 
*  Jerry				2010-4-13   
* Note:
*    
*/
const PLC_PARAMS_T *plc_api_params_get( void )
{
	return (const PLC_PARAMS_T *)plc_if_params_get();
}
#if (defined(XN5106C_EXT)) && defined(MASTER_NODE)
/*
* Function Name:
*   plc_api_master_params_get
* Description:
*   PLC master Parameters Get
* Parameters:
* Returns:
*   const PLC_MASTER_PARAMS_T*:
* Author				Date 
*  Nicky				2012-9-5   
* Note:
*    
*/
const PLC_MASTER_PARAMS_T *plc_api_master_params_get( void )
{
	return (const PLC_MASTER_PARAMS_T *)plc_if_master_params_get();
}
#endif
/*
* Function Name:
*   plc_api_sig_info_get
* Description:
*   Signal Quality and vit chg get
* Parameters:
*   U8* p_sig_quality:
*   U8* p_vit_chg:
* Returns:
* Author				Date 
*  Jerry				2010-4-13   
* Note:
*    
*/
void plc_api_sig_info_get( U8 *p_sig_quality, U8 *p_vit_chg )
{
	*p_sig_quality = plc_pl_sig_quality_get();
	*p_vit_chg = plc_pl_vit_chg_get();
}


/*
* Function Name:
*   plc_node_route_info
* Description:
*   Slave node route info
* Parameters:
*   MAC_ADDR_T* p_mac_addr: Pointed slave node mac address
*   U8* p_relay_n: return relay number
*   NODE_INFO_T* p_node_info: return relay node info
* Returns:
*   BOOL:
* Author				Date 
*  Jerry				2009-11-4   
* Note:
*    
*/
BOOL plc_node_route_info( MAC_ADDR_T *p_mac_addr, U8 *p_relay_n, \
						  NODE_INFO_T *p_node_info )
{
	return TRUE;
}

